package com.example.demo.Springmytbatis.mapper;

import com.example.demo.Springmytbatis.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    //查询所有用户
    @Select("select id,username,'password',age,gender,phone,delete_flag,create_time,update_time from user_info")
    public List<UserInfo> queryAllUser();


    @Select("select * from user_info")
    List<UserInfo> getAllUser();
//    @Select("select * from user_info")
//    UserInfo getAllUser2();


    @Select("select * from user_info where id=#{id}")
    UserInfo getUserInfoById(Integer id);

    @Select("select * from user_info where id='${id}'")
    UserInfo getUserInfoById2(Integer id);

    @Select("select * from user_info where id=#{aa}")
   List<UserInfo> getUserInfoById3(Integer id);

    @Select("select * from user_info where username=#{param2} and password=#{param1}")
    List<UserInfo> getUserByNameAndPassword(String password,String username);

    //参数发生重绑定
    @Select("select * from user_info where userName='${param2}' and password='${param1}'")
    List<UserInfo> getUserByNameAndPassword2(String password,@Param("userName") String username);

    //传递对象
    @Select("SELECT * FROM user_info WHERE username = #{username} AND password = #{password}")
    List<UserInfo> getUserByUserInfo(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username,password,age) values(#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username,password,age) values(#{user.username},#{user.password},#{user.age})")
    Integer insertUser2(@Param("user") UserInfo userInfo);

    @Delete("delete from user_info where id=#{id}")
    Integer deleteUser(Integer id);


    @Update("update user_info set delete_flag=#{deleteFlag},phone=#{phone} where id=#{id}" )
    Integer updateUser(UserInfo userInfo);

    @Select("SELECT* from user_info where username='${username}' and password='${password}'")
    List<UserInfo> selectByUserNameandBypassword(String username,String password);

    @Select("SELECT* from user_info ORDER BY id ${sort}")
    List<UserInfo> sortdesc(String desc);

    @Select("SELECT* from user_info ORDER BY id #{sort}")
    List<UserInfo> sortdesc1(String desc);

    @Select("SELECT * from user_info where username like '%#{key}%'")
    List<UserInfo> mohuchaxun(String key);

    @Select("SELECT * from user_info where username like concat('%',#{key},'%')")
    List<UserInfo> mohuchaxun2(String key);


//    @Insert("<script>"+
//            "INSERT into user_info "+
//            ""
//    )
//    Integer insertUserByCondition2(UserInfo userInfo);


}

